package com.lzb.browser.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.browser.BaseAc;
import com.lzb.browser.Content;
import com.lzb.browser.R;
import com.lzb.browser.basic.utils.SPUtil;
import com.lzb.browser.databinding.ActivitySetBackupPswBinding;

public class SetBackupPswActivity extends BaseAc<ActivitySetBackupPswBinding> implements View.OnClickListener {

    public static String password;
    private String backupPassword;

    @Override
    protected int onCreate() {
        return R.layout.activity_set_backup_psw;
    }

    @Override
    protected void initView() {
        mDataBinding.ivSetBackupPswBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvNotNeed.setOnClickListener(this);
        mDataBinding.tvClear.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvNotNeed) {//不需要备用密码
            SPUtil.putBoolean(mContext, Content.isHavePassword, true);
            SPUtil.putBoolean(mContext, Content.isEnablePassword, true);
            SPUtil.putString(mContext, Content.myPassword, password);
            startActivity(SettingActivity.class);
            finish();
        } else if (id == R.id.tvClear) {//清除
            mDataBinding.etPassword.setText("");
        } else if (id == R.id.tvConfirm) {//确定
            backupPassword = mDataBinding.etPassword.getText().toString();
            if (TextUtils.isEmpty(backupPassword)) {
                ToastUtils.showShort(getString(R.string.please_input_backup_password));
                return;
            }
            if (backupPassword.length() < 4) {
                ToastUtils.showShort(getString(R.string.please_input_min_four_password));
                return;
            }
            SPUtil.putBoolean(mContext, Content.isHavePassword, true);
            SPUtil.putBoolean(mContext, Content.isEnablePassword, true);
            SPUtil.putString(mContext, Content.myPassword, password);
            SPUtil.putString(mContext, Content.myBackupPassword, backupPassword);
            startActivity(SettingActivity.class);
            finish();
        }
    }

    @Override
    protected void initData() {

    }
}